package com.vmladenov.cook.core.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class DataHelper
{
	private DatabaseHelper helper;
	private SQLiteDatabase userDb;

	public RecipesRepository RecipesRepository;
	public SpicesRepository SpicesRepository;
	public ProductsRepository ProductsRepository;
	public AdvicesRepository AdvicesRepository;
	public ShoppingListsRepository ShoppingListsRepository;

	public DataHelper(Context context)
	{
		this.helper = new DatabaseHelper(context);
		this.userDb = helper.getWritableDatabase();
		RecipesRepository = new RecipesRepository();
		SpicesRepository = new SpicesRepository();
		ProductsRepository = new ProductsRepository();
		AdvicesRepository = new AdvicesRepository();
		ShoppingListsRepository = new ShoppingListsRepository(userDb);
	}

	public void close()
	{
		this.ShoppingListsRepository.close();
		if (userDb.isOpen()) userDb.close();
		helper.close();
	}
}
